<?php

/**
 * Will return the requested language item
 * @param String $key
 * @param Boolean $show_errors
 */
function lang($key, $show_errors = FALSE) {
	$lang = AkaiKiwi::loadLib('Language');
	if($lang->is_loaded()) {
		try {
			return $lang->get($key);
		} catch(AkaikiwiException $e) {
			return $show_errors ? 'Language Error: ' . $e->getMessage() : NULL;
		}
	} else {
		return $show_errors ? 'Language Error: No language file loaded' : NULL;
	}
}

/**
* Will create a small javascript script containing the requested keys
* @param String $keys comma separated keys
*/
function js_lang($keys = NULL) {
	if($keys == NULL) {
		$lang = AkaiKiwi::loadLib('Language');
		$keys = implode(',', array_keys($lang->get_lang_array()));
	}
	
	$r = '<script type="text/javascript" language="javascript" charset="utf-8">';
	foreach(explode(',', $keys) as $key) {
		$r .= 'var lang_'.trim($key).'="'.lang(trim($key)).'";';
	}
	$r .= '</script>';
	return $r;
}
